package com.coincalf.web.agent;

import com.baomidou.mybatisplus.plugins.Page;
import com.coincalf.dto.ResultDTO;
import com.coincalf.entity.Account;
import com.coincalf.framework.security.UserDetails;
import com.coincalf.service.AccountService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 * 代理商账户资产 前端控制器
 * </p>
 *
 * @author qiang
 * @since 2018-04-17
 */
@RestController
@RequestMapping("/agent/account")
@Api(value = "代理商账户资产", description = "代理商账户资产")
public class AgentAccountController {

    @Autowired
    private AccountService accountService;

    /**
     * 查询所有下级代理商用户
     *
     * @param userDetails
     * @return
     */
    @GetMapping(value = "/levelUser")
    @ApiOperation(value = "代理商-查询当前用户下所有代理列表", httpMethod = "GET", authorizations = {@Authorization(value = "Authorization")})
    public ResultDTO levelUser(@ApiIgnore @AuthenticationPrincipal UserDetails userDetails) {
        return ResultDTO.successResult(accountService.selectAllLevelUser(userDetails.getId()));
    }

    /**
     * 查询代理商账户资产
     *
     * @param page        分页参数
     * @param coinId      币种ID
     * @param userName    用户名
     * @param createTime  创建时间
     * @param parentId    上级ID
     * @param userDetails 当前登录用户
     * @return
     */
    @GetMapping(value = "/userAccount")
    @ApiOperation(value = "代理商-查询账户资产", httpMethod = "GET", authorizations = {@Authorization(value = "Authorization")})
    @ApiImplicitParams({@ApiImplicitParam(name = "current", value = "当前页码", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页大小", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "coinId", value = "币种类型ID", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "用户名称", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "上级ID", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "时间", dataType = "String", paramType = "query")})
    public ResultDTO getUserAccount(@ApiIgnore Page<Account> page,
                                    Integer coinId,
                                    String userName,
                                    String createTime,
                                    Integer parentId,
                                    @ApiIgnore @AuthenticationPrincipal UserDetails userDetails) {
        return ResultDTO.successResult(accountService.selectAccountByNames(page, coinId, userName, userDetails.getId(), createTime, parentId));
    }

    /**
     * 代理商账户资产统计
     *
     * @param userDetails
     * @return
     */
    @GetMapping(value = "/accountTotal")
    @ApiOperation(value = "代理商-账户资产统计", httpMethod = "GET", authorizations = {@Authorization(value = "Authorization")})
    public ResultDTO accountTotal(@ApiIgnore @AuthenticationPrincipal UserDetails userDetails) {
        return accountService.selectAccountTotal(userDetails.getId());
    }
}

